home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / comm / news / slrn-BIN.lha / slrn-BIN-0.9.7.4 / contrib / slrnrc-conv < prev   
Text File  |  2001-11-03  |  4KB  |  167 lines

  1. #! /usr/bin/perl -w
  2. #
  3. # slrnrc-conv - converts an old ~/.slrnrc file to new format
  4. #
  5. # by Matthias Friedrich <matt@mafr.de>
  6. #
  7. # Usage: perl slrnrc-conv ~/.slrnrc > new_config
  8. #
  9. use strict;
  10.  
  11. #
  12. # group functions conversation table
  13. #
  14. my %group = (
  15.     down          =>    'line_down',
  16.     group_bob     =>    'bob',
  17.     group_eob     =>    'eob',
  18.     group_search  =>    'group_search_forward',
  19.     pagedown      =>    'page_down',
  20.     pageup        =>    'page_up',
  21.     toggle_group_display => 'toggle_group_formats',
  22.     uncatch_up    =>    'uncatchup',
  23.     up            =>    'line_up'
  24. );
  25.  
  26. #
  27. # article functions conversation table
  28. #
  29. my %article = (
  30.     art_bob                 =>   'article_bob',
  31.     art_eob                 =>   'article_eob',
  32.     art_xpunge              =>   'article_expunge',
  33.     article_linedn          =>   'article_line_down',
  34.     article_lineup          =>   'article_line_up',
  35.     article_pagedn          =>   'article_page_down',
  36.     article_pageup          =>   'article_page_up',
  37.     down                    =>   'header_line_down',
  38.     enlarge_window          =>   'enlarge_article_window',
  39.     goto_beginning          =>   'article_bob',
  40.     goto_end                =>   'article_eob',
  41.     left                    =>   'article_left',
  42.     locate_header_by_msgid    =>   'locate_article',
  43.     pagedn                  =>   'header_page_down',
  44.     pageup                  =>   'header_page_up',
  45.     pipe_article            =>   'pipe',
  46.     prev                    =>   'previous',
  47.     print_article           =>   'print',
  48.     right                   =>   'article_right',
  49.     scroll_dn               =>   'article_page_down',
  50.     scroll_up               =>   'article_page_up',
  51.     shrink_window           =>   'shrink_article_window',
  52.     skip_to_prev_group      =>   'skip_to_previous_group',
  53.     toggle_show_author      =>   'toggle_header_formats',
  54.     up                      =>   'header_line_up'
  55. );
  56.  
  57. #
  58. # variable conversation table
  59. #
  60. my %variables = (
  61.     process_verbatum_marks    =>    'process_verbatim_marks',
  62.     followup        =>    'followup_string'
  63. );
  64.  
  65. #
  66. # obsolete variables that can't be rewritten automatically
  67. # they will be commented out and an explanatory message is printed to stderr
  68. #
  69. my %obsolete_variables = (
  70.     prompt_next_group    =>
  71.         'The feature controlled by this variable has been removed.',
  72.     query_reconnect        =>
  73.         'There is no need to confirm reconnects anymore.',
  74.     use_xgtitle        =>
  75.         'slrn does not use XGTITLE anymore.',
  76.     author_display        =>
  77.         'Please use the %f escape of header_display_format.',
  78.     display_author_realname    =>
  79.         'Please use the %r escape of header_display_format.',
  80.     display_score        =>
  81.         'Please use the %S escape of header_display_format.',
  82.     group_dsc_start_column    =>
  83.         'Please customize group_display_format instead.',
  84.     show_descriptions    =>
  85.         'Please use the %d escape of group_display_format.'
  86. );
  87.  
  88.  
  89. #
  90. # colors conversation table
  91. #
  92. my %colors = (
  93.     verbatum        =>    'verbatim'
  94. );
  95.  
  96. #
  97. # obsolete commands, rewrite them to variables
  98. #
  99. my @commands = (
  100.                  'hostname', 'username', 'replyto',
  101.                  'organization', 'scorefile', 'signature',
  102.                  'realname', 'followup', 'cc_followup_string',
  103.                  'quote_string', 'decode_directory', 'editor_command'
  104.                );
  105.  
  106.  
  107. # regexps that match a (possibly quoted) string
  108. my $str_rx = '\S+';
  109. my $qstr_rx = '"(?:\\\\|\\.|.)*"|\S+';
  110.  
  111. # read input file line by line
  112. while ( <> )
  113. {
  114.     # rewrite key bindings
  115.     if ( m/^(\s*setkey\s*"?)(group|article)("?\s*"?)([^\s"]+)(\s*.*)$/ )
  116.     {
  117.         if ( $2 eq 'group' and $group{$4} )
  118.         {
  119.             $_ = "$1$2$3$group{$4}$5\n";
  120.         }
  121.         elsif ( $2 eq 'article' and $article{$4} )
  122.         {
  123.             $_ = "$1$2$3$article{$4}$5\n";
  124.         }
  125.     }
  126.     # rewrite color names
  127.     elsif ( m/^(\s*color\s*)(${qstr_rx})(.*)$/ )
  128.     {
  129.         my $name = $colors{$2} || $2;
  130.  
  131.         $_ =  "$1${name}$3\n";
  132.     }
  133.     # rewrite variable names
  134.     elsif ( m/^(\s*set\s*)(${qstr_rx})(.*)$/ )
  135.     {
  136.         my $why;
  137.         my $name = $variables{$2} || $2;
  138.         
  139.         $_ = "$1${name}$3\n";
  140.  
  141.         if ( $why = $obsolete_variables{$name} )
  142.         {
  143.             print STDERR "The variable $name is obsolete.\n",
  144.                 "\t$why\n";
  145.  
  146.             print "% slrnrc-conv: The variable $name ",
  147.                 "is obsolete.\n", "% $why\n";
  148.             $_ = '% ' . $_;
  149.         }
  150.     }
  151.     # probably this is a command, rewriting doesn't even need a table
  152.     elsif ( m/^(\s*)(${str_rx})(.*)$/ )
  153.     {
  154.         my $cmd = $2;
  155.         my $set = '';
  156.  
  157.         $set = 'set ' if grep {m/$cmd/} @commands;
  158.  
  159.         $_ = "$set$1$2$3\n";
  160.  
  161.         redo if $set; # maybe the resulting variable needs rewriting
  162.     }
  163.     # no else case needed, simply print line
  164.  
  165.     print;
  166. }
  167.